function [y,signal]=bpskrcos(LN,L,SNR,W)
%根升余弦成型的BPSK调制系统
%返回值y为误码率，signal为发送信号引
data = randi ([0,1],1,LN);
%产生随机数作为发送数据
data_bipolar = 1 -2*data;
%将数据转为双极性序列，0对应于1,1对应于-1
data_upsample = upsample(data_bipolar,L);
rcos_fir = rcosfir(0.6,6,L,1,'sqrt');
%产生根升余弦被形
rconv = conv(data_upsample,rcos_fir);
%完成根升余弦成型
carrier = cos(2*pi*W*(1:length(rconv)) );
%产生载波
Rsend = rconv.*carrier;
%完成BPSK调制
Rrecv = awgn(Rsend,SNR,'measured');
%通过信道，加噪
data_rec = Rrecv.*carrier;
%接收信号与本地载被相乘
data_rconv = conv(data_rec,rcos_fir);
%接收端通过接收匹配滤波器进行解调
rdata_biplolar = downsample(data_rconv,L);
%采样
rdata(rdata_biplolar<0)=1;rdata(rdata_biplolar>0)=0;%
Rdata = rdata(13:LN+12);
c=0;
%误码率计算
for n=1:LN
    if (data(n)~=Rdata(n))
        c=c+1;
    end
end
y=c/LN;
signal = Rsend;